//检查一个点周围是否平坦，如果传入小于0，则取反，等于0代表不检查
//满足返回true

params ["_pos", "_dis"];


if(surfaceIsWater _pos) exitWith{false};

if(_dis == 0) exitWith{true};

private ["_pos_z", "_pos_temp", "_pos_temp_z", "_ret", "_dt_x", "_dt_y", "_dis_2", "_count"];

_ret = false;
_count = 0;
_dis_2 = 2 * _dis;

_pos_z = (AGLToASL [_pos select 0, _pos select 1, 0]) select 2;

#define DH 0.5
#define CHECK_NUM 24
#define OK_NUM 18

if(_dis < 0) then
{
	_dis = -_dis;
	for "_i" from 1 to CHECK_NUM do 
	{ 
		_dt_x = (random _dis_2) - _dis;
		_dt_y = (random _dis_2) - _dis;
		_pos_temp = [((_pos select 0) + _dt_x), ((_pos select 1) + _dt_y), 0];
		if(!surfaceIsWater _pos_temp) then
		{
			_pos_temp_z = (AGLToASL _pos_temp) select 2;
			if(abs(_pos_temp_z - _pos_z) > DH) then
			{
				_count = _count + 1;
			};
		};
	};
	
	if(_count > OK_NUM) then
	{
		_ret = true;
	};
}
else
{
	for "_i" from 1 to CHECK_NUM do 
	{ 
		_dt_x = (random _dis_2) - _dis;
		_dt_y = (random _dis_2) - _dis;
		_pos_temp = [((_pos select 0) + _dt_x), ((_pos select 1) + _dt_y), 0];
		if(!surfaceIsWater _pos_temp) then
		{
			_pos_temp_z = (AGLToASL _pos_temp) select 2;
			if(abs(_pos_temp_z - _pos_z) < DH) then
			{
				_count = _count + 1;
			};
		};
	};
	
	if(_count > OK_NUM) then
	{
		_ret = true;
	};
	
};

_ret
